package com.fatkun;
/**
 * 鍦℅AE涓婃姄鍙栫綉鍧�
 * @author Fatkun
 * @site http://fatkun.com
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import javax.servlet.http.*;

@SuppressWarnings("serial")
public class HttpURLServlet extends HttpServlet {
	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String line;
		StringBuffer sb = new StringBuffer();
		resp.setContentType("text/plain; charset=utf-8");

		try {
			URL url = new URL("http://jiage.me/PriceList/price.php?type=icbcyin&time=2011-11-03%2023:55:46&platform=%20HTTP/1.1\\r\\n");
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			connection.setDoInput(true);// 浣跨敤 URL 杩炴帴杩涜杈撳叆
			connection.setRequestMethod("GET");
			// 鍙栧緱缃戦〉婧愮爜
			BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
			if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
				// 姣忔璇诲彇涓�杈撳嚭
				while ((line = reader.readLine()) != null) {
					sb.append(line).append("\n");
				}
				reader.close();
			} else {
				// Server returned HTTP error code.
			}
			connection.disconnect();
		} catch (MalformedURLException e) {

		} catch (IOException e) {

		}

		resp.getWriter().println(sb.toString());
	}
}
